﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using RestSharp;
using TheNorthStar.Api.Requests;
using TheNorthStar.Api.Results;

namespace NorthStar.Driver.Application
{
    public class ConnectToSever
    {
         private RestClient _client;
        public ConnectToSever(string server)
        {
           // _client = new RestClient("http://137.92.181.228/TheNorthStar");
            _client = new RestClient(server);
        }
        public string DriverLogingOn( DriverLogon driver )
        {
            var request = new RestRequest("drivers/logon", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddObject(driver);
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
        public string ComfirmLogginOn(DriverLogon driver)
        {
            var request = new RestRequest("cardetails/getcar", Method.POST);
            request.RequestFormat = DataFormat.Json;
            Cars car = new Cars();
            car.carNum = driver.carNum;
            request.AddObject(car);
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
        public string SetDriverStatus(DriverLogon driver)
        {
            var request = new RestRequest( "drivers/setdriverstatus", Method.POST );
            request.RequestFormat = DataFormat.Json;
            request.AddObject( driver );
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
        public string AcceptAJob(DriverLogon driver, Booking booking)
        {
            var request = new RestRequest("drivers/acceptbooking", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddObject(driver);
            request.AddObject( booking );
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
        public string TryAcceptJob(string DriverId, string bookingId)
        {
            var request = new RestRequest("drivers/acceptbooking", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddObject(new {driverId = DriverId, BookingId = bookingId});
            
            RestResponse response = _client.Execute(request);
            return response.Content;
        }

        public string RequestWork( DriverMoreWorkRequest driver )
        {
            var request = new RestRequest( "drivers/requestwork", Method.POST );
            request.RequestFormat = DataFormat.Json;
            request.AddObject( driver );
            RestResponse response = _client.Execute( request );
            return response.Content;
        }
        public string GetCustomerAddress(Booking booking)
        {
            var request = new RestRequest("drivers/getcustomeraddress", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddObject(booking);
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
        public string CompleteJob(DriverLogon driver, Booking booking)
        {
            var request = new RestRequest("drivers/completejob", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddObject(driver);
            request.AddObject(booking);
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
        public string PickedUpBooking(DriverLogon driver, Booking booking)
        {
            var request = new RestRequest("drivers/pickedupbooking", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddObject(driver);
            request.AddObject(booking);
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
        public string NoShow(DriverLogon driver, Booking booking)
        {
            var request = new RestRequest("drivers/noshow", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddObject(driver);
            request.AddObject(booking);
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
        public void UpdatePosition(DriverPosition driverPosition)
        {
            var request = new RestRequest("drivers/updateposition", Method.POST);
            request.RequestFormat = DataFormat.Json;
            request.AddObject(driverPosition);
            
            RestResponse response = _client.Execute(request);
        }

        public string GetBooking(int refId)
        {
            var request = new RestRequest("bookings/{id}");
            request.AddUrlSegment("id", refId.ToString());
            request.RequestFormat = DataFormat.Json;
            RestResponse response = _client.Execute(request);
            return response.Content;
        }
    }
}
